import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { RenderType } from '@pkg/setting';

export const columns: BasicColumn[] = [
  {
    title: '补录时间',
    dataIndex: 'createTime',
    width: 150,
  },
  {
    title: '使用时间',
    dataIndex: 'useDate',
    width: 150,
  },
  {
    title: '审核状态',
    dataIndex: 'isCheck',
    width: 120,
    customRender: ({ record }: Recordable) => {
      const isCheckArray = [
        { label: '待审核', value: 0 },
        { label: '审核通过', value: 1 },
        { label: '审核拒绝', value: 2 },
      ];
      const isCheck: any = isCheckArray.find(item => item.value == record.isCheck);
      if (isCheck) {
        return isCheck.label;
      }
      return '';
    },
  },
  {
    title: '会员姓名',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '归属销售',
    dataIndex: 'haveCheckEmployee',
    dictData: [
      { label: '无', value: 0, color: '#ee0303' },
      { label: '有', value: 1, color: '#032aee' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '会员手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '证件号',
    dataIndex: 'identityNo',
    width: 170,
  },
  {
    title: '卡号',
    dataIndex: 'vipCardNo',
    width: 150,
  },
  {
    title: '服务名称',
    dataIndex: 'serverName',
    width: 150,
  },
  {
    title: '使用次数',
    dataIndex: 'useNum',
    width: 100,
  },
  {
    title: '使用机场',
    dataIndex: 'airportName',
    width: 150,
  },
  {
    title: '核销员工',
    dataIndex: 'employeeName',
    width: 120,
  },
  {
    title: '目标名称',
    dataIndex: 'targetName',
    width: 120,
  },
  {
    title: '类型',
    dataIndex: 'optType',
    width: 120,
    customRender: ({ record }: Recordable) => {
      const optTypeArray = [
        { label: '补录', value: 1 },
        { label: '减录', value: 2 },
      ];
      const optType: any = optTypeArray.find(item => item.value == record.optType);
      if (optType) {
        return optType.label;
      }
      return '';
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 120,
  },
  {
    title: '审核人类型',
    dataIndex: 'checkUserType',
    dictData: [
      { label: '销售端', value: 1, color: '#ad5419' },
      { label: '后台', value: 2, color: '#09d550' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '审核人',
    dataIndex: 'checkUserName',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'userInfo',
    label: '会员信息',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'identityNo',
    label: '证件号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'vipCardNo',
    label: '卡号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'serverName',
    label: '服务名称',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'isCheck',
    label: '审核状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '待审核', value: 0 },
        { label: '审核通过', value: 1 },
        { label: '审核拒绝', value: 2 },
      ],
    },
  },
  {
    field: 'optType',
    label: '录入类型',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '补录', value: 1 },
        { label: '减录', value: 2 },
      ],
    },
  },
  {
    field: 'haveCheckEmployee',
    label: '归属销售',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '有', value: 1 },
        { label: '无', value: 0 },
      ],
    },
  },
  {
    field: 'airportId',
    label: '开卡地区',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: airportList,
      params: { handlerName: 'busAirportRoleListHandler' },
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  },

  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '会员卡号',
    field: 'vipCardNo',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '所属机场',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange: airportId => {
          formModel.employeeId = null;
        },
      };
    },
  },
  {
    label: '使用时间',
    field: 'useDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];
